package com.yinhe.music.yhmusic.radio.presenter;

import com.yinhe.music.yhmusic.base.BasePresenter;
import com.yinhe.music.yhmusic.base.IBaseModel;
import com.yinhe.music.yhmusic.network.response.ResponseTransformer;
import com.yinhe.music.yhmusic.radio.contract.IRadioSongContract;

/**
 * @author 何晓华
 */
public class RadioSongPresenter extends BasePresenter<IBaseModel, IRadioSongContract.IRadioSongView> implements IRadioSongContract.IRadioSongPresenter {

    @Override
    public void getRadioSong(int id, int pageSize, int page) {
        if (getView() == null) {
            return;
        }

        if (page == 1){
            getView().showLoading();
        }

        addSubscription(mModel.getRadioSong(id, pageSize, page)
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(radioSongs -> {
                    getView().hideLoading();
                    getView().setRadioSongUI(radioSongs);
                }, throwable -> {
                    getView().hideLoading();
                    getView().showMessage(throwable);
                }));
    }
}
